// miniprogram/pages/teacher/teacher.js
const db=wx.cloud.database()
const _=db.command
Page({
  toTeacher2: function(){
    wx.navigateTo({
      url: '../teacher2/teacher2'
    })
  },
  toTeacher3: function(){
    wx.navigateTo({
      url: '../teacher3/teacher3'
    })
  },
  onAgree: function(ev){
   const index=ev.target.dataset.index;
   const that=this;
   const regis=this.data.regises[index];
   const _id=regis._id;
   wx.cloud.callFunction({
    name: 'saveRegis',
    data: {
      _id:_id,
      regis:regis
    },
    success: res=>{
      let regises=that.data.regises;
      regises.splice(index,1);
      that.setData({
        regises: regises
      })
      wx.showToast({
        title: '成功!',
      })
    }
   })
  },
  onRefuse: function(ev){
    const index=ev.target.dataset.index;
    const that=this;
    const regis=this.data.regises[index];
    const _id=regis._id;
    wx.cloud.callFunction({
     name: 'removeRegis',
     data: {
       _id:_id,
       regis:regis
     },
     success: res=>{
       let regises=that.data.regises;
       regises.splice(index,1);
       that.setData({
         regises: regises
       })
       wx.showToast({
         title: '完成!',
       })
     }
    })
  },
  onJobAgree: function(ev){
    const index=ev.target.dataset.index;
    const that=this;
    const job=this.data.jobs[index];
    const _id=job._id;
    wx.cloud.callFunction({
     name: 'saveJob',
     data: {
       _id:_id,
       job:job
     },
     success: res=>{
       let jobs=that.data.jobs;
       jobs.splice(index,1);
       that.setData({
         jobs: jobs
       })
       wx.showToast({
         title: '成功!',
       })
     }
    })
  },
  onJobRefuse: function(ev){
    const index=ev.target.dataset.index;
    const that=this;
    const job=this.data.jobs[index];
    const _id=job._id;
    wx.cloud.callFunction({
     name: 'removeJob',
     data: {
       _id:_id,
       job:job
     },
     success: res=>{
       let jobs=that.data.jobs;
       jobs.splice(index,1);
       that.setData({
         jobs: jobs
       })
       wx.showToast({
         title: '完成!',
       })
     }
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    regises: [],
    jobs: [],
    speeches: []
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that=this;
    //获取企业注册审核
    wx.cloud.callFunction({
      name: 'getRegis',
      success: res=>{
        const regises=res.result.data;
        that.setData({
           regises: regises
        })
      
      }
    })
    //获取岗位发布审核
    wx.cloud.callFunction({
      name: 'getJobs',
      success: res=>{
        const jobs=res.result.data;
        that.setData({
          jobs: jobs
        })
      
      }
    })
    wx.cloud.callFunction({
      name: 'getSpeeches',
      success: res=>{
        const speeches=res.result.data;
        that.setData({
          speeches: speeches
        })
        
      
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onImgTap: function(ev){
    const that=this;
    const pindex=ev.target.dataset.pindex;
    const index=ev.target.dataset.index;
    const current=that.data.regises[pindex].images[index];
    wx.previewImage({
      urls: that.data.regises[pindex].images,
      current: current
    })
  },
  feedbackSpeech: function(ev){
    const feedback=ev.detail.value.feedback;
  },
  

})